package com.jiankangjin.transsystem.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jiankangjin.encryptKit.EncryptUtil;
import com.jiankangjin.transsystem.services.UpdOrderInfoServices;
import com.jiankangjin.transsystem.vo.UpdOrderInfoVo;

/**
 * 更改商品明细 zfy
 */
@Controller
public class UpdOrderInfoController {
	private static final Log log = LogFactory.getLog(CreateOrderController.class);
	
	@Autowired
	private UpdOrderInfoServices updOrderInfoServices;

	@RequestMapping(value = "/upder_OrderDataInfo", method = RequestMethod.POST)
	@ResponseBody
	public UpdOrderInfoVo updOrderDetailInfo(
			@RequestParam(required = false) String token,
			@RequestParam(required = false) String order_id,
			@RequestParam(required = false) String detail,
			@RequestParam(required = false) String content,
			@RequestParam(required = false) String comment,
			@RequestParam(required = false) String sign) {
		UpdOrderInfoVo updOrderInfoVo = new UpdOrderInfoVo();
		if (log.isInfoEnabled()) {
			StringBuffer sb = new StringBuffer();
			sb.append("token=").append(token);
			sb.append("order_id=").append(order_id);
			sb.append("detail=").append(detail);
			sb.append("content=").append(content);
			sb.append("comment=").append(comment);
			sb.append("sign=").append(sign);
			log.info("调用修改商品明细接口" + sb);
		}
		try {
			if(StringUtils.isEmpty(order_id)){
				updOrderInfoVo.setResp_status("9999");
				updOrderInfoVo.setMsg("订单号不能为空！");
			}
			if (!StringUtils.isEmpty(detail)) {
				if (detail.indexOf(":") == -1) {
					byte[] dData = EncryptUtil.dByPrivateKey(detail.getBytes("utf-8"), "");
					if (dData == null) {
						log.error("，detail[" + detail + "]商户明细解密失败");
						updOrderInfoVo.setMsg("，detail[" + detail + "]商户明细解密失败");
						updOrderInfoVo.setResp_status("9999");
						return updOrderInfoVo;
					}
				}
			} else {
				updOrderInfoVo.setMsg("商品明细不能为为空，请重新输入商品明细！");
				updOrderInfoVo.setResp_status("9999");
			}
			return updOrderInfoServices.updOrderDetailInfo(token, order_id, detail, content, comment, sign);
		} catch (Exception e) {
			updOrderInfoVo.setMsg("系统错误！");
			updOrderInfoVo.setResp_status("9999");
			e.printStackTrace();
			return updOrderInfoVo;
		}
	}

}
